home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / apps / 356 / applic / getflsz.pas < prev    next >
Pascal/Delphi Source File  |  1989-02-16  |  2KB  |  54 lines

  1. PROCEDURE GetFileSize(FileName : path_name;
  2.             VAR NbrBytesInFile : long_integer);
  3.   {Get the length of a file in bytes.  The file name in a standard Pascal
  4.   form is provided as a parameter.}
  5. TYPE
  6.   pack14 = PACKED ARRAY[1..14] OF char;
  7.   cstring = PACKED ARRAY[1..80] OF char;
  8.   DTA_Type = PACKED RECORD
  9.                reserved : PACKED ARRAY[0..19] OF byte;
  10.                resvd    : byte;
  11.                Attribute: byte;
  12.                Time     : integer;
  13.                Date     : integer;
  14.                FileSize : long_integer;
  15.                F_Name   : pack14;
  16.              END {record};
  17.   S80 = string[80];
  18.  
  19. VAR
  20.   Addr       : DTA_Type;
  21.   Attributes : byte;
  22.   S2         : s80;
  23.   C_FileName : cstring;
  24.   Status   : integer;
  25.  
  26.   PROCEDURE StrToC_String(Name1 : Path_Name; VAR Name2 : CString);
  27.     {Convert a Pascal string to a null terminated character array}
  28.     VAR i,l : integer;
  29.     BEGIN
  30.       L := LENGTH(Name1);
  31.       FOR i := 1 TO L DO
  32.         Name2[i] := Name1[i];
  33.       Name2[L+1] := CHR(0);
  34.     END {strtoc_string};
  35.  
  36.   PROCEDURE SetDTA(VAR Addr : DTA_Type);
  37.     GEMDOS($1A);
  38.  
  39.   FUNCTION SearchFirst(VAR FileName   : cstring;
  40.                            Attributes : integer)
  41.                            : integer;
  42.     GEMDOS($4E);
  43.  
  44.   BEGIN {getfilesize}
  45.     SetDTA(Addr);
  46.     StrToC_String(FileName,C_FileName);
  47.     Attributes := $07;
  48.     Status := SearchFirst(C_FileName,Attributes);
  49.     IF Status <> 0
  50.       THEN
  51.         WriteLn('Error on getting file size from OS. Status:',Status);
  52.     NbrBytesInFile := Addr.FileSize;
  53.   END {getfilesize};
  54.